package ch.elca.lol.puissance4.game;

import ch.elca.lol.puissance4.util.Util;

class Delayer {
	private long lastTick = 0;
	
	private long time() {
		return System.currentTimeMillis();
	}
	
	public void tick() {
		lastTick = time();
	}
	
	public void delay(long delay) {
		if(delay == -1) {
			Util.stdinNextLine();
		} else {
			long elapsed = time() - lastTick;
			long toSleep = delay - elapsed;
			if(toSleep <= 0)
				return;
			
			try {
				Thread.sleep(toSleep);
			} catch(InterruptedException e) {
				// Ignore
			}
		}
	}
}
